package com.d3works.apps.account.service;

import com.d3works.apps.account.db.Invoice;
import com.d3works.apps.account.db.Umr;
import com.d3works.apps.base.service.AddressServiceImpl;
import com.d3works.db.JPA;

public class AddressServiceAccountImpl extends AddressServiceImpl {
  static {
    registerCheckUsedFunc(AddressServiceAccountImpl::checkAddressUsedAccount);
  }

  private static boolean checkAddressUsedAccount(Long addressId) {
    return JPA.all(Invoice.class).filter("self.address.id = ?1", addressId).fetchOne() != null
        || JPA.all(Umr.class).filter("self.debtorAddress.id = ?1", addressId).fetchOne() != null;
  }
}
